package org.srtc.infopub.datacenter.storage;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;

public class TestCoalLeavesTable {

	private HashMap<String, ArrayList<String>> map;
	
	private TestCoalTable tct;
	
	private TestQuitTable tqt;
	
	public TestCoalLeavesTable(String coalXML) {
		map = new HashMap<String, ArrayList<String>>();
		tct = new TestCoalTable(coalXML);
		tqt = new TestQuitTable();
	}
	
	
	/**
	 * 得到矿所有叶子
	 * @param dirPath 信息类配置文件所在目录
	 * @return 没有叶节点则返回null
	 */
	public HashMap<String, ArrayList<String>> coalLeaves(String dirPath) {
		
		if (tct.getCoals().isEmpty()) {
			tct.coalInfos();
		}
		if (tqt.quitTable.isEmpty()) {
			tqt.createQuitTable(dirPath);
		}
		
		Iterator<Entry<String, ArrayList<String>>> it = tct.getCoals().entrySet().iterator();
		while (it.hasNext()) {
			ArrayList<String> list = new ArrayList<String>();
			
			Entry<String, ArrayList<String>> en = it.next();
			ArrayList<String> infos = en.getValue();
		
			for (int i = 0; i<infos.size(); i++) {
				ArrayList<String> leaves = tqt.quitTable.get(infos.get(i) + ".");
				list.addAll(leaves);
			}
			map.put(en.getKey(), list);
		}
		
		return map;
	}
	
	
	public HashMap<String, ArrayList<String>> getMap() {
		return map;
	}


	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		TestCoalLeavesTable tclt = new TestCoalLeavesTable("copy-gzmxx.xml");
		tclt.coalLeaves("xml");
		System.out.println(tclt.getMap());
	}

}
